qtre.input = {

	canvas : null,

	dx : 0,

	dy : 0,

	mouseDown : false,

	mouseMove : false,

	shiftKey : false,

	altKey : false,

	ctrlKey : false,

	_keyDown : {},

	wheelDelta : 0,

	initialize : function(canvas){
		this.canvas = canvas;
		
		var that = this;

		canvas.addEventListener("mousemove", function(event){
			if(!qtre.core.isset(that.offsetX)){
				that.offsetX = event.offsetX;
				that.offsetY = event.offsetY;
				that.clientX = event.clientX;
				that.clientY = event.clientY;
			}
			that.dx = event.clientX - that.clientX;
			that.dy = event.clientY - that.clientY;
			
			that.offsetX = event.offsetX;
			that.offsetY = event.offsetY;

			that.clientX = event.clientX;
			that.clientY = event.clientY;

			that.shiftKey = event.shiftKey;
			that.altKey = event.altKey;
			that.ctrlKey = event.ctrlKey;
			
		})

		canvas.addEventListener("mouseup", function(event){
			that.shiftKey = event.shiftKey;
			that.altKey = event.altKey;
			that.ctrlKey = event.ctrlKey;

			that.mouseDown = false;
		})

		canvas.addEventListener("mousedown", function(event){
			that.shiftKey = event.shiftKey;
			that.altKey = event.altKey;
			that.ctrlKey = event.ctrlKey;

			that.mouseDown = true;
		})

		canvas.addEventListener("mousewheel", function(event){
			that.shiftKey = event.shiftKey;
			that.altKey = event.altKey;
			that.ctrlKey = event.ctrlKey;

			that.wheelDelta = event.wheelDelta;
		})

		document.addEventListener("keydown", function(event){
			that._keyDown[event.keyCode] = true;
			that.shiftKey = event.shiftKey;
			that.ctrlKey = event.ctrlKey;
			that.altKey = event.altKey;
		})

		document.addEventListener("keyup", function(event){
			that._keyDown[event.keyCode] = false;
			that.shiftKey = event.shiftKey;
			that.ctrlKey = event.ctrlKey;
			that.altKey = event.altKey;
		})
	},

	dispatchEvent : function(){
		//dispatch mouse event,
		var event = document.createEvent("MouseEvents");
		event.initEvent("mousemove", true, true);
		this.canvas.dispatchEvent(event)
	},

	checkKey : function(keyCode){
		if(this._keyDown[keyCode]){
			return true;
		}
		return false;
	},

	addEventListener : function(eventType, func){
		this.canvas.addEventListener(eventType, func);
	},

	removeEventListener : function(eventType, func){
		this.canvas.removeEventListener(eventType, func);
	}
}